//
//  WelcomeView.swift
//  微博
//
//  Created by admin on 2018/3/26.
//  Copyright © 2018年 xm. All rights reserved.
//

import UIKit
import SDWebImage

class WelcomeView: UIView {

    @IBOutlet weak var headImage: UIImageView!
    @IBOutlet weak var heaImageWithCons: NSLayoutConstraint!
    @IBOutlet weak var tipLable: UILabel!
    @IBOutlet weak var headImageCons: NSLayoutConstraint!
    
    /// 类方法，从xlib实例化当前对象
    ///
    /// - Returns: xlib实例
    class func welcomeView() -> WelcomeView{
        let nib = UINib(nibName:"WelcomeView", bundle: nil)
        let v=nib.instantiate(withOwner: nil, options: nil)[0] as! WelcomeView
        v.frame=UIScreen.main.bounds
        return v;
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        if let imgurl=NetworkManager.shared.userAccount.avatar_large,
           let url=URL(string: imgurl)
            {
          //设置头像图片
         headImage.setImageWith(url, placeholderImage: UIImage(named: "avatar_default_big"))
        }
        //设置头像圆角
        headImage.clipsToBounds=true
        headImage.layer.cornerRadius = heaImageWithCons.constant/2
    }
    
    
    /// 初始化完毕，挂载到window上了
    override func didMoveToWindow() {
        super.didMoveToWindow()
        self.layoutIfNeeded()
        tipLable.alpha=0.0  
        UIView.animate(withDuration: 1.0, animations: {
           self.headImageCons.constant=self.bounds.height-200
           self.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 1.0, animations: {
                 self.tipLable.alpha=1.0
            }, completion: { (_) in
                 //删除欢迎视图
                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+0.5, execute: {
                    self.removeFromSuperview()//删除视图
                })
            })
        }
    }

}
